package com.huadao.cart_ccs.experiment.confirmBeforeCulture;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBar;
import android.view.View;
import android.widget.TextView;

import com.huadao.cart_ccs.R;
import com.huadao.cart_ccs.base.BaseActivity;
import com.huadao.cart_ccs.experiment.confirmBeforeCulture.environmentDevice.EnvironmentDeviceFrag;
import com.huadao.cart_ccs.experiment.confirmBeforeCulture.orderList.OrderListFrag;
import com.huadao.cart_ccs.experiment.confirmBeforeCulture.produceInfo.ProduceInfoFrag;
import com.huadao.cart_ccs.experiment.confirmBeforeCulture.rawMaterial.RawMaterialFrag;
import com.huadao.cart_ccs.experiment.home.ExperimentActivity;
import com.huadao.cart_ccs.experiment.paramsSetting.SetParamsActivity;

public class ConfirmBeforeCultureActivity extends BaseActivity implements OrderListFrag.ConfirmOrderList, ProduceInfoFrag.ConfirmProduceInfo, EnvironmentDeviceFrag.ConfirmEnvironmentDevice, RawMaterialFrag.ConfirmRawMaterial {

    private TextView tv_title;
    private FragmentManager fragmentManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_confirm_before_culture);
        initActionBar();
        fragmentManager=getSupportFragmentManager();
//        OrderListFrag orderListFrag=new OrderListFrag();
//        orderListFrag.setConfirmOrderList(this);
//        replaceFrag(orderListFrag);
//        tv_title.setText("指令单和生产信息");
        tv_title.setText("生产信息");
        ProduceInfoFrag produceInfoFrag=new ProduceInfoFrag();
        produceInfoFrag.setConfirmProduceInfo(this);
        replaceFrag(produceInfoFrag);
    }

    private void initActionBar() {
        toolbar = findViewById(R.id.toolbar);
        if (toolbar != null) {
            findViewById(R.id.back).setVisibility(View.GONE);
            findViewById(R.id.setting).setVisibility(View.GONE);
            tv_title = findViewById(R.id.title);
            setSupportActionBar(toolbar);
            ActionBar actionBar = getSupportActionBar();
            if (actionBar != null) {
                actionBar.setDisplayShowTitleEnabled(false);
            }
        }
    }

    private void replaceFrag(Fragment fragment){
        fragmentManager.beginTransaction().setCustomAnimations(R.anim.slide_in_right,R.anim.slide_out_left).replace(R.id.fl_confirm,fragment).commit();
    }

    @Override
    public void onConfirmOrderList() {
//        ProduceInfoFrag produceInfoFrag=new ProduceInfoFrag();
//        produceInfoFrag.setConfirmProduceInfo(this);
//        replaceFrag(produceInfoFrag);
//        tv_title.setText(R.string.produceInfo);
        onConfirmProduceInfo();
    }

    @Override
    public void onConfirmProduceInfo() {
//        EnvironmentDeviceFrag environmentDeviceFrag=new EnvironmentDeviceFrag();
//        environmentDeviceFrag.setConfirmEnvironmentDevice(this);
//        replaceFrag(environmentDeviceFrag);
//        tv_title.setText(R.string.environmentDevice);
        RawMaterialFrag rawMaterialFrag=new RawMaterialFrag();
        rawMaterialFrag.setConfirmRawMaterial(this);
        replaceFrag(rawMaterialFrag);
        tv_title.setText("物料确认");
    }

    @Override
    public void onConfirmEnvironmentDevice() {
        RawMaterialFrag rawMaterialFrag=new RawMaterialFrag();
        rawMaterialFrag.setConfirmRawMaterial(this);
        replaceFrag(rawMaterialFrag);
        tv_title.setText(R.string.rawMaterial);
    }

    @Override
    public void onConfirmRawMaterial() {
        Intent intent=new Intent(this,SetParamsActivity.class);
        startActivity(intent);
        finish();
    }
}
